package com.jiayi.weiphoto.service;

import java.util.ArrayList;

import android.widget.Adapter;
import android.widget.BaseAdapter;

import com.jiayi.weiphoto.entity.ImageEntity;

public class KepianCache {
	
	ArrayList<BaseAdapter> adapters = new ArrayList<BaseAdapter>();
	
	public void addAdapter(BaseAdapter adapter){
		if(!adapters.contains(adapter)){
			adapters.add(adapter);
		}
	}
	
	private KepianCache(){}
	
	static KepianCache cache;
	
	public static KepianCache getInstance(){
		if(cache == null){
			cache = new KepianCache();
		}
		return cache;
	}
	
	private ArrayList<ImageEntity> picUrlList = new ArrayList<ImageEntity>();

	public ArrayList<ImageEntity> getPicUrlList() {
		return picUrlList;
	}

	public void dump() {
		// TODO Auto-generated method stub
		for(ImageEntity imgEntity : picUrlList){
			if(imgEntity.getPic() != null && !imgEntity.getPic().isRecycled()){
				imgEntity.getPic().recycle();
				imgEntity.setPic(null);
			}
		}
		for(BaseAdapter adapter : adapters){
			adapter.notifyDataSetChanged();
		}
		adapters.clear();
		picUrlList.clear();
	}
}
